<template>
  <map :scale="scale" :polygons="funGeometryList" id="map" ref="map" :latitude="latitude" :longitude="longitude"
       :style="fullStyle">
  </map>
</template>

<script>
import {baseMixins} from "@/mixins/baseMixins";
import {requestGet} from "@/util/request";
import {GET_MESSAGE_INFO} from "@/api";

export default {
  mixins: [baseMixins],
  data() {
    return {
      scale: 11,
      center: null,
      latitude: 0,
      longitude: 0,
      chitId: '',
      rings: [],
      funGeometryList: []
    }
  },
  methods: {
    loadData() {
      return new Promise((resolve, reject) => {
        requestGet({
          url: GET_MESSAGE_INFO,
          data: {id: this.chitId}
        }).then(res => {
          if (res != null && res.data != null && res.data.geoDataList != null && res.data.geoDataList.length > 0) {
            this.rings = res.data.geoDataList[0].rings
          } else {
            uni.$u.toast('无保单数据');
          }
          resolve()
        })
      })

    },
    addGeometry() {
      let {rings} = this
      rings.forEach(ringList => {
        let polygon = {}
        let points = []
        ringList.forEach(point => {
          let [longitude, latitude] = point
          if (this.center == null) {
            this.center = {longitude, latitude}
          }
          points.push({
            longitude,
            latitude
          })
        })
        polygon = {
          points,
          strokeWidth: 2,
          strokeColor: '#12FCFCFF',
          fillColor: '#12FCFC19'
        }
        this.funGeometryList.push(polygon)
      })
      console.log(this.funGeometryList)
      this.latitude = this.center.latitude
      this.longitude = this.center.longitude
    },
  },
  onLoad(queryParams) {
    this.chitId = queryParams.chitId
  },
  async onReady() {
    await this.loadData()
    if (this.rings.length > 0) {
      this.addGeometry()
    }
  },
}
</script>

<style scoped lang="scss">
.index-root {
}
</style>
